<template>
	<div class="card">
		<div class="phone-content">
			<div class="avatar">
				<image v-if="message.messageContent.extra == 'phone'" style="width: 100%; height: 100%;" src="../../phone.png" alt=""  mode="scaleToFill"/>
				<image v-else style="width: 100%; height: 100%;" src="../../wx.png" alt=""  mode="scaleToFill"/>
			</div>
			<div class="phone-content-title">
				我想要你的{{ message.messageContent.extra == "phone" ? "电话" : "微信" }}，你是否同意？
			</div>
		</div>
		<div class="buttons">
			<div class="button" @click="refuse">拒绝</div>
			<div class="button" @click="agree">同意</div>
		</div>
	</div>
</template>

<script>
	import wfc from "@/wfc/client/wfc";
	import store from "@/store";
	import Draft from "../../../util/draft";
	import QuoteInfo from "@/wfc/model/quoteInfo";
	import covertContactMessage from "@/wfc/messages/covertContactMessage";
	import {
		getJobContact,
		getInteractionDic,
		setImInteraction,
	} from "@/common/im";
	import { req } from '@/common/vmeitime-http/'
	import api from '@/common/api.js'
	import { userStore } from "@/pinia";
	
	export default {
		name: "NormalInMessageContentView",
		props: {
			message: null,
			jobContactData: {},
			jobId:null,
			dfid:null,
		},
		data() {
			return {
				sharedConversationState: store.state.conversation,
				phone:'',
				wechatNumber:'',
				realName:''
			};
		},
		mounted() {
			const userStoreInfo = userStore();
			if(userStoreInfo.userFlag==0){
				req('GET',api.meiyeRecruitHunterInfo2Details,{
						userId: userStoreInfo.userInfo.id
					}).then(res=>{
					console.log('我的个人信息是',res);
					this.realName = res.result.realName
					this.phone = res.result.phone
					this.wechatNumber = res.result.wechatNumber
				})
			}else{
				req('GET',api.meiyeRecruitHrInfo3QueryById,{
						id: userStoreInfo.userInfo.id
					}).then(res=>{
					console.log('我的个人信息是',res);
					this.realName = res.result.realName
					this.phone = res.result.phone
					this.wechatNumber = res.result.wechatNumber
				})
			}
		},
		methods: {
			getJobContactData(type, isReversed = false) {
				console.log("this.jobContactData: >>", this.jobContactData);
				const field = getInteractionDic(type, isReversed);
				return this.jobContactData[field];
			},
			// 拒绝
			refuse() {
				const field = getInteractionDic(this.message.messageContent.extra);
				setImInteraction(field, -1,this.jobId,this.dfid);
				this.send("-1");
			},
			// 同意
			agree() {
				console.log('同意了');
				const field = getInteractionDic(this.message.messageContent.extra);
				setImInteraction(field, 2,this.jobId,this.dfid);
				const type = this.message.messageContent.extra;
				if (type == "phone") {
					this.send(JSON.stringify({phone:this.phone,name:this.realName}));
				} else if (type == "wx") {
					this.send(JSON.stringify({wechatNumber:this.wechatNumber,name:this.realName}));
				}
			},
			send(text) {
				let phoneMessageContent;
				const type = this.message.messageContent.extra;
				if (type == "phone") {
					phoneMessageContent = new covertContactMessage("phone", text);
				} else if (type == "wx") {
					phoneMessageContent = new covertContactMessage("wx", text);
				}
				let quotedMessage = this.sharedConversationState.quotedMessage;
				if (quotedMessage) {
					let quoteInfo = QuoteInfo.initWithMessage(quotedMessage);
					phoneMessageContent.setQuoteInfo(quoteInfo);
					store.quoteMessage(null);
				}

				let currentConversation =
					this.sharedConversationState.currentConversationInfo.conversation;

				wfc.sendConversationMessage(currentConversation, phoneMessageContent);
				this.text = "";
				this.mentions = [];
				Draft.setConversationDraft(currentConversation, "", null);
				store.loadConversationHistoryMessages(()=>{},()=>{});
			},

		},
	};
</script>

<style scoped>
</style>